#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2018, Niklas Hauser
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# -----------------------------------------------------------------------------

def init(module):
    module.name = ":communication:xpcc"
    module.description = "Cross Platform Component Communication (XPCC)"

def prepare(module, options):
    module.depends(
        ":architecture:can",
        ":container",
        ":debug",
        ":io", # from generated robot_packets.hpp
        ":math:utils",
        ":processing:resumable",
        ":processing:timer")

    module.add_option(
        NumericOption(
            name="timeout.acknowledge",
            description="Timeout in ms of an reception acknowledgement",
            minimum=10, maximum=10000,
            default=100))

    module.add_option(
        NumericOption(
            name="timeout.response",
            description="Timeout in ms of an request response",
            minimum=10, maximum=10000,
            default=200))

    return True

def build(env):
    env.outbasepath = "modm/src/modm/communication/xpcc"

    ignore = ["*.in", "*backend/tipc*"]

    if env[":target"].identifier["platform"] in ["avr"]:
        ignore.append("*postman/dynamic*")

    env.copy(".", ignore=env.ignore_paths(*ignore))
    env.copy("../xpcc.hpp")
    env.template("dispatcher.hpp.in")
